﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Text;
using DotNETX.Authentication.Db.MySql;

namespace DotNETX.Authentication.Db
{
    public class MySqlUserManager : DbUserManager
    {
        public override string CreateParam(IDbCommand cmd, string paramName, object paramValue)
        {
            return DotNETX.Authentication.Db.MySql.ParameterUtils.CreateParam(cmd, paramName, paramValue);
        }

        public override bool TryOpenConnection(IDbConnection con)
        {
            return base.TryOpenConnection(con);
        }

        public static DbUserManager Create(string server, string database, string uid, string pwd, string table, string loginid_col, string pwd_col, string uniqueid_col, string userFilter = null)
        {
            return Create(ConnectionUtils.CreateMySqlConnection(server, database, uid, pwd), table, loginid_col, pwd_col, uniqueid_col, userFilter);
        }
        
        public static DbUserManager Create(string connectionString, string table, string loginid_col, string pwd_col, string uniqueid_col, string userFilter = null)
        {
            return Create(ConnectionUtils.CreateMySqlConnection(connectionString), table, loginid_col, pwd_col, uniqueid_col, userFilter);
        }

        public static DbUserManager Create(IDbConnection conn, string table, string loginid_col, string pwd_col, string uniqueid_col, string userFilter = null)
        {
            return new MySqlUserManager()
            {
                Connection = conn,
                TableName = table,
                LoginIdColumn = loginid_col,
                PasswordColumn = pwd_col,
                UniqueIdColumn = uniqueid_col,
                UserFilter = userFilter
            };
        }
    }
}
